/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-05-06     liuchao       the first version
 */
#ifndef APPLICATIONS_CONFIGURATION_H_
#define APPLICATIONS_CONFIGURATION_H_
#include "at24cxx.h"

typedef enum
{
    CONFIGURATION_START,
    CONFIGURATION_MQTT_HOST = CONFIGURATION_START,
    CONFIGURATION_MQTT_PORT,
    CONFIGURATION_MQTT_CLIENT_ID,
    CONFIGURATION_MQTT_USER_NAME,
    CONFIGURATION_MQTT_PASSWD,
    // 油压
    CONFIGURATION_SENSOR_OIL_PRESSURE_BASELINE,
    // 油缸位移
    CONFIGURATION_SENSOR_PUTTER_DISTANCE_BASELINE,
    // 齿轮位移
    CONFIGURATION_SENSOR_GEAR_DISTANCE_BASELINE,
    // 油温
    CONFIGURATION_SENSOR_OIL_TEMP_BASELINE,
    // 油量
    CONFIGURATION_SENSOR_OIL_VOLUME_BASELINE,
    // 油压2
    CONFIGURATION_SENSOR_OIL_PRESSURE_2_BASELINE,
    // 轴力系数K
    CONFIGURATION_AXIAL_K,
    // 轴力系数b
    CONFIGURATION_AXIAL_B,
    CONFIGURATION_MQTT_PRODUCT_SECRET,
    CONFIGURATION_MQTT_DEVICE_SECRET,
    CONFIGURATION_PUTTER_DISTANCE_MIN,
    CONFIGURATION_PUTTER_DISTANCE_MAX,
    CONFIGURATION_UP_COUNTS,
    CONFIGURATION_RUN_SECONDS,
    CONFIGURATION_HY_RUN_MS,
    CONFIGRATION_END
} configuration_e;

typedef enum
{
    CONFIGURATION_TYPE_STR, CONFIGURATION_TYPE_UINT32, CONFIGURATION_TYPE_FLOAT
} configuration_type_e;

const char* configuration_name(configuration_e configuration);
configuration_type_e configuration_type(configuration_e configuration);

char* configuration_get(configuration_e configuration);
rt_err_t configuration_set(configuration_e configuration, const char* value);
rt_uint32_t configuration_get_uint32(configuration_e configuration);
rt_err_t configuration_set_uint32(configuration_e configuration, rt_uint32_t value);
float configuration_get_float(configuration_e configuration);
rt_err_t configuration_set_float(configuration_e configuration, float value);

int configuration_is_mqtt_host_valid();
float configuration_putter_distance_min();
float configuration_putter_distance_max();

void configuration_dump();

float auto_mode_baseline();
rt_err_t auto_mode_set_baseline(float v);
float auto_mode_percentage();
rt_err_t auto_mode_set_percentage(float v);
#define AUTO_MODE_UPDATE_INTERVAL_THD (120)
rt_int32_t auto_mode_update_inverval();
rt_err_t auto_mode_set_update_interval(rt_int32_t v);
rt_int32_t auto_mode_update_delay();
rt_err_t auto_mode_set_update_delay(rt_int32_t v);
rt_int32_t rotate_handled();
rt_err_t rotate_set_handled(rt_int32_t v);
rt_int32_t axial_is_met();
rt_err_t axial_set_is_met(rt_int32_t v);
time_t axial_met_ts();

rt_uint32_t up_counts();

rt_uint32_t sleep_seconds_get();
rt_err_t sleep_seconds_set(rt_uint32_t v);

void pause_switch_set(int state);
int pause_switch_get();

void release_pressure_set(int value);
int release_pressure_get();
void go_back_seconds_set(int seconds);
int go_back_seconds_get();

void configuration_reset_counter();

void battery_low_threshold_set(float v);
float battery_low_threshold_get();
#endif /* APPLICATIONS_CONFIGURATION_H_ */
